package com.qf.air.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 创建ElasticSearch的客户端
 */
@Configuration
public class ElasticsearchConfig {

    @Value("${elasticsearch.host}")
    private String host;

    @Value("${elasticsearch.port}")
    private int port;


    @Bean
    public RestHighLevelClient getClient(){
        //1. httpHost
        HttpHost httpHost = new HttpHost(host,port);
        //2. RestClientBuilder
        RestClientBuilder builder = RestClient.builder(httpHost);
        //3. RestHighLevelClient
        RestHighLevelClient client = new RestHighLevelClient(builder);
        //4. return
        return client;
    }

}
